package TCP02;

import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author 宋鑫宇
 * @version 1.0
 * 完成Socket 网络编程入门案例的客户端开发，实现多发多收
 */
public class ClientDome1 {
    public static void main(String[] args) throws Exception{
        //1.创建Socket 通信管道请求有服务端的链接
        Socket socket = new Socket("127.0.0.1", 7777);

        //2.从Socket 管道得到一个字节输出流
        OutputStream outputStream = socket.getOutputStream();

        //3.把低级的字节流包装成打印流
        PrintStream printStream = new PrintStream(outputStream);
        Scanner scanner = new Scanner(System.in);
        String msg;
        while (true) {
            System.out.println("请输入发送信息：");
            msg = scanner.next();
            if ("exit".equals(msg)){
                break;
            }
            //4.发送消息
            printStream.println(msg);
        }

        //5.关闭资源,谨慎关闭
//        socket.close();
    }
}
